<template>
	<view>
		<view v-if="couponList.length">
			<view class="unuse-coupon" v-for="(item,index) in couponList" :key="index"
				@click="showCodeFn(item.couponCheckCode)">
				<view class="coupon-title">
					<text>{{item.policyName}}</text>
					<text>面值:{{item.value}}元</text>
				</view>
				<view class="coupon-rule">
					<text>有效期至:{{item.useEndDate}}</text>
					<text>销售时间:{{item.saleTime}}</text>
				</view>
				<view class="coupon-tip">
					<text>(点击获取核销码)</text>
				</view>
			</view>
		</view>

		<view class="no-data" v-else>
			<text>暂无优惠券</text>
		</view>
		<u-overlay :show="showCode" @click="showCode=false">
			<view class="ticket-pop">
				<view class="ticket-info">
					<view class="verifyCode">
						<text>核销码：{{qrCode}}</text>
					</view>
					<view class="code-box">
						<view class="qr-code">
							<view v-show="!isVerificated">
								<uqr-code size="160" :text="qrCode" :show='true'>
								</uqr-code>
							</view>
							<view v-show="isVerificated">
								<image src="../../static/image/cant.png" style="width: 160px;" mode="widthFix"></image>
							</view>
						</view>
						<image class="verificated" v-show="qrCode!='' && isVerificated"
							src="../../static/image/hexiao.png" mode="widthFix"></image>

					</view>
				</view>

				<image src="../../static/image/ticket_bg.png" class="ticket_bg"></image>
			</view>
		</u-overlay>
	</view>
</template>

<script>
	import UqrCode from '../uqrcode/uqrcode.vue'
	export default {
		props: ['couponList'],
		components: {
			UqrCode
		},
		data() {
			return {
				showCode: false,
				qrCode: ''
			};
		},
		methods: {
			showCodeFn(code) {
				this.showCode = true
				this.qrCode = code
			},
		}
	}
</script>

<style lang="scss">
	.ticket-pop {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100vw;
		height: 100vh;

		.ticket_bg {
			position: absolute;
			width: 100vw;
			height: 60vh;
			z-index: -1;
		}

		.ticket-info {
			width: 100vw;
			height: 60vh;
			display: flex;
			flex-direction: column;
			align-items: center;
			box-sizing: border-box;
			padding-top: 120rpx;
			position: relative;

			.verifyCode {
				display: flex;
				flex-direction: column;
				padding: 15rpx;
				border: 2px solid #cacaca;
				border-radius: 30rpx;

			}

			.code-box {
				margin-top: 180rpx;
				position: relative;
				display: flex;
				flex-direction: column;
				align-items: center;

				.qr-code {
					position: absolute;
					z-index: 0;
				}

				.verificated {
					width: 100px;
					z-index: 999;
					position: absolute;
					right: -100px;
					top: -30px;
				}
			}

			.tips {
				position: absolute;
				bottom: 160rpx;
			}
		}
	}

	.no-data {
		width: 100vw;
		text-align: center;

		text {
			line-height: 140rpx;
			font-size: 26rpx;
			color: #999;
		}
	}

	.unuse-coupon {
		width: 90vw;
		padding: 20rpx;
		background-color: #fff;
		margin: 15rpx auto 0 auto;
		border-radius: 15rpx;

		.coupon-title {
			display: flex;
			justify-content: space-between;
			font-size: 28rpx;
			border-bottom: 1px solid #f0f0f5;

			text {
				line-height: 60rpx;
			}
		}

		.coupon-rule {
			font-size: 28rpx;
			color: #999;
			border-bottom: 1px solid #f0f0f5;

			text {
				display: inline-block;
				line-height: 60rpx;
			}
		}

		.coupon-tip {
			text-align: right;
			font-size: 24rpx;

			text {
				line-height: 50rpx;
				color: #999;
			}
		}
	}

	.used-coupon {
		width: 90vw;
		padding: 20rpx;
		background-color: #fff;
		margin: 15rpx auto 0 auto;
		border-radius: 15rpx;
		color: #999;

		.coupon-title {
			display: flex;
			justify-content: space-between;
			font-size: 28rpx;
			border-bottom: 1px solid #f0f0f5;

			text {
				line-height: 60rpx;
			}
		}

		.coupon-rule {
			font-size: 28rpx;

			// border-bottom:1px solid #f0f0f5; 
			text {
				display: inline-block;
				line-height: 60rpx;
			}
		}
	}
</style>